<!--
 * @Date: 2019-12-26 11:44:30
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-04-29 10:31:56
 * @describe: -状态变更-
 -->
<template>
  <div class="stateUpdate">
    <el-form :model="dataForm" label-width="100px" label-position="left">
      <el-form-item
        :label="dataForm.sortType?$getDictLabel('houseSortType',dataForm.sortType):'姓名：'"
      >
        <!-- {{$getDictLabel("houseSortType",dataForm.sortType)?$getDictLabel("houseSortType",dataForm.sortType):''  +'姓名：'}} -->
        <el-input v-model="dataForm.ownerName" clearable></el-input>
      </el-form-item>
      <el-form-item
        :label="dataForm.sortType?$getDictLabel('houseSortType',dataForm.sortType)+'电话1':'电话1'"
      >
        <el-input v-model="dataForm.ownerPhone1" clearable></el-input>
      </el-form-item>
      <el-form-item
        :label="dataForm.sortType?$getDictLabel('houseSortType',dataForm.sortType)+'电话2':'电话2'"
      >
        <el-input v-model="dataForm.ownerPhone2" clearable></el-input>
      </el-form-item>

      <el-form-item
        :label="dataForm.sortType?$getDictLabel('houseSortType',dataForm.sortType)+'电话3':'电话3'"
      >
        <el-input v-model="dataForm.ownerPhone3" clearable></el-input>
      </el-form-item>

      <el-form-item label="面积">
        <el-input v-model="dataForm.area" clearable @change="Setprices"></el-input>
      </el-form-item>
      <el-form-item label="单价">
        <el-input v-model="dataForm.price" clearable @change="Setprices"></el-input>
      </el-form-item>
      <el-form-item label="总价">
        <el-input v-model="dataForm.prices" clearable>
          <span slot="suffix" class="imgNull">{{transactionType == 0?'万元':'元'}}</span>
        </el-input>
      </el-form-item>
      <el-form-item label="房屋现状">
        <ren-select
          v-model="dataForm.situation"
          dict-type="dictSituation"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <el-form-item label="公私盘">
        <ren-select
          v-model="dataForm.commonState"
          dict-type="houseCommonState"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <!-- <el-form-item label="交易类型">
                <ren-select
                    v-model="dataForm.transactionType"
                    dict-type="houseTransactionType"
                    class="FormSelect"
                    style="width:100%"
                ></ren-select>
      </el-form-item>-->
      <el-form-item label="状态">
        <ren-select
          v-model="dataForm.state"
          dict-type="dictState"
          placeholder="状态"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button
          @click="stateUpdateFun"
          style="width:100%;"
          type="primary"
        >保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      transactionType: this.$route.query.transactionType,
      type: this.$route.query.type,
      dataForm: {
        // houseId: this.HousingID,
        houseId: this.$route.query.ID,
        area: "",
        ownerName: "",
        ownerPhone1: "",
        ownerPhone2: "",
        ownerPhone3: "",
        price: "",
        prices: "",
        situation: "",
        transactionType: "",
        state: "",
        commonState: ""
      },
      AxiosUrl: ""
    };
  },
  props: ["permissionListDTO"],
  created() {
    this.getInfo();
  },
  mounted() {},
  methods: {
    // 获取数据
    getInfo() {
      this.getUrl();
      this.$http
        .get(this.AxiosUrl, {
          params: {
            houseId: this.dataForm.houseId
          }
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.dataForm = res.data;
        })
        .catch(() => {});
    },

    //修改核心
    stateUpdateFun() {
      this.$http
        .put("/house/houseinfo/housecCore", this.dataForm)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              // this.$refs["dataForm"].resetFields();
            }
          });
        })
        .catch(() => {});
    },
    Setprices() {
      if (this.transactionType == "0") {
             this.dataForm.prices = (this.dataForm.area * this.dataForm.price) / 10000;
      } else if (this.transactionType == "1") {
          //出租
           this.dataForm.prices = (this.dataForm.area * this.dataForm.price);
        }
     
    },
    getUrl() {
      if (this.type == "2") {
        //住宅
        if (this.transactionType == "0") {
          //出售
          this.AxiosUrl = "/house/houseinfo/homeSellInfo";
        } else if (this.transactionType == "1") {
          //出租
          this.AxiosUrl = "/house/houseinfo/homeLeaseInfo";
        }
      } else if (this.type == "0") {
        //写字楼
        if (this.transactionType == "0") {
          //出售
          this.AxiosUrl = "/house/houseinfo/officeSellInfo";
        } else if (this.transactionType == "1") {
          //出租
          this.AxiosUrl = "/house/houseinfo/officeLeaseInfo";
        }
      } else if (this.type == "1") {
        //公寓
        if (this.transactionType == "0") {
          //出售
          this.AxiosUrl = "/house/houseinfo/homeSellInfo";
        } else if (this.transactionType == "1") {
          //出租
          this.AxiosUrl = "/house/houseinfo/homeLeaseInfo";
        }
      }
    },
    //判断操作权限
    hasPermissionInfo(val) {
      let _this = this;
      let arr = _this.permissionListDTO;
      if (arr && arr != []) {
        for (let i = 0; i < arr.length; i++) {
          const element = arr[i];
          if (element.permission.indexOf(val) != -1 && element.state == true) {
            return true;
          }
        }
      } else {
        return false;
      }
    }
  },
  watch: {
    $route(to, from) {
      if (to.name == "HousingPages") {
        this.dataForm.houseId = this.$route.query.ID;
        this.transactionType = this.$route.query.transactionType;
        this.type = this.$route.query.type;
        this.getInfo();
      }
    }
  },
  activated() {}
};
</script>
<style scoped>
.stateUpdate {
  width: 500px;
  margin: auto;
}
</style>